import request from '@/utils/request'

export function getDeviceBySn(sn) {
  return request({
    url: `/devices/sn/${sn}`,
    method: 'get'
  })
}

export function getDeviceByChannel(channel) {
  return request({
    url: `/devices/channel/${channel}`,
    method: 'get'
  })
}

export function getDevices(listQuery) {
  return request({
    url: '/devices',
    method: 'get',
    params: listQuery
  })
}

export function getStatus(house) {
  return request({
    url: '/status',
    method: 'get',
    params: {
      house: house
    }
  })
}
export function getDeviceStatus(house) {
  return request({
    url: '/device/status',
    method: 'get',
    params: {
      house: house
    }
  })
}

export function configDevice(device) {
  return request({
    url: `/devices/${device.id}`,
    method: 'put',
    params: device
  })
}

export function remarkDevice(id, remarks) {
  return request({
    url: `/devices/${id}/remark`,
    method: 'put',
    params: {
      remarks: remarks
    }
  })
}

export function deleteDevice(id) {
  return request({
    url: `/devices/${id}`,
    method: 'delete'
  })
}

export function batchAdd(devices) {
  return request({
    url: '/devices',
    method: 'post',
    data: devices
  })
}

export function getLogs(deviceId, start) {
  return request({
    url: `/devices/${deviceId}/logs`,
    method: 'get',
    params: {
      start: start
    }
  })
}

export function startDevice(device) {
  return request({
    url: `/status/start`,
    method: 'get',
    params: device
  })
}

export function stopDevice(device) {
  return request({
    url: `/status/stop`,
    method: 'get',
    params: device
  })
}

export function removeDevice(device) {
  return request({
    url: `/status/remove`,
    method: 'get',
    params: device
  })
}

export function restoreDevice(device) {
  return request({
    url: `/status/restore`,
    method: 'get',
    params: device
  })
}

export function batchDetach(devices) {
  return request({
    url: `/status/batchDetach`,
    method: 'post',
    data: devices
  })
}

export function startAll(devices) {
  return request({
    url: `/status/startAll`,
    method: 'post',
    data: devices
  })
}

export function stopAll(devices) {
  return request({
    url: `/status/stopAll`,
    method: 'post',
    data: devices
  })
}

export function sendAlarm(device) {
  return request({
    url: `/status/alert`,
    method: 'get',
    params: device
  })
}

export function getChannelStatus(channels) {
  return request({
    url: '/status/channels',
    method: 'post',
    data: channels
  })
}


export function exportHistoryData(params) {
  return request({
    url: `/devices/history/export`,
    method: 'get',
    responseType: 'blob',
    params
  })
}

export function exportDeviceData(device, start) {
  return request({
    url: `/devices/${device.id}/logs/export`,
    method: 'get',
    responseType: 'blob',
    params: {
      start: start,
      sn: device.sn,
      channel: device.channel
    }
  })
}

export function stopAlarm() {
  return request({
    url: '/status/stopAlarm',
    method: 'get'
  })
}

export function getTemperatures(cabinet) {
  return request({
    url: '/status/getTprs',
    method: 'get',
    params: {
      cabinet
    }
  })
}

export function getPowerState(cabinet) {
  return request({
    url: '/status/getPowerState',
    method: 'get',
    params: {
      cabinet
    }
  })
}
